/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Test;

import UDPFiles.UDPFileReader;
import UDPFiles.UDPFileWriter;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author wcss
 */
public class UDPFileRWTest
{
    public static void main(String[] args)
    {
        try {
            UDPFileReader ufr = new UDPFileReader(new File("/home/wcss/视频/QvodMovies/aliedit.tar.gz"));
            ufr.open();
            long packcount = ufr.getLength() / 500;
            if (ufr.getLength() % 500 > 0)
            {
                packcount += 1;
            }
            
            if (new File("/home/wcss/UDPTest_B/temp.dat").exists())
            {
                new File("/home/wcss/UDPTest_B/temp.dat").delete();
            }
            
            if (new File("/home/wcss/UDPTest_B/aliedit.tar.gz").exists())
            {
                new File("/home/wcss/UDPTest_B/aliedit.tar.gz").delete();
            }
            
            UDPFileWriter ufw = new UDPFileWriter(new File("/home/wcss/UDPTest_B/temp.dat"),new File("/home/wcss/UDPTest_B/aliedit.tar.gz"),5000);
            ufw.init(packcount);
            
            for(int k = 0;k < packcount;k++)
            {
                byte[] source = ufr.readPack(k * 500);
                ufw.writeBytes(k * 500, source);
            }
            ufw.makeDestFile(0);
            
            ufr.close();
        } catch (Exception ex) {
            Logger.getLogger(UDPFileRWTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        
    }
    
}
